import React, { Component } from 'react'
import "./index.css"
export default class Footer extends Component {
    // 清除所有已完成任务的回调
    handleClearAllDone=()=>{
        if(window.confirm("是否删除已完成的任务")){
            this.props.clearAllDone()
        }
    }
    // 全选功能
    handleCheckAll=(event)=>{
        this.props.checkAll(event.target.checked)
    }
    render() {
        const {todos}=this.props;
        let finished=todos.reduce((pre,todo)=>pre+(todo.done?1:0),0)
        let allTodo=todos.length;
        return (
            <div className="todo-footer">
                <label>
                    <input type="checkbox" onChange={this.handleCheckAll} checked={allTodo===finished&&allTodo>0 ?true:false}/>
                </label>
                <span>
                    <span>已完成{finished}</span> / 全部{allTodo}
                </span>
                <button onClick={this.handleClearAllDone} className="btn btn-danger">清除已完成任务</button>
            </div>
        )
    }
}
